<template>
<!-- 打款审核新增页面弹框 -->
  <div>
    <div>
      <FormPanel
        ref="from"
        :list="initForm"
        :cols="1"
        :isSubmitBtn="false"
        :collapse="false"
        :formType="actionType"
      />
    </div>
    <div class="dialogBottmView">
      <el-button :loading="loadingFlag" @click="save()" type="primary">保 存</el-button>
      <el-button @click="closeDialog('closeDialog')">返 回</el-button>
    </div>
  </div>
</template>
<script>

import { dictionary } from '@/utils/dictMixin';
import { numberCheckMax100,positiveInteger } from '@/utils/validate';
import { addOrEditPartReturnParam } from '@/api/partsmanage/trafficParams/categoryRepair/index';

export default {
  props:{
    actionType: {
      type: String,
      required: true,
      default: ""
    },
    row: {
      type: Object,
      required: false,
      default: null
    },
  },
  data(){
    return{
      initForm:this.createdFrom(),
      loadingFlag:false,
    }
  },
  created(){
    if(this.actionType == "edit"){
      this.init(this.row);
    }
  },
  mixins:[dictionary],
  methods:{
    init(row){
      this.initForm.forEach(x => {
        if (x.fieldName === 'partTypeName') {
          x.initialValue = row.partTypeName
        }
      })
    },
    async save(){//保存
        if(this.loadingFlag){
            return notifyAction('已有操作在进行中请稍后!', 'warning');
        }
        //表单校验
        let [err, data] = await this.$refs.from.GET_FORM_DATA();
        if(err) return;
        this.loadingFlag = true;
        if(this.actionType == "add"){
          data.mark = "add";
        } else {
          data.mark = "edit";
          data.id = this.row.id;
        }
        let result = await addOrEditPartReturnParam(data);
        if (result.resultCode === 200) {
          this.$notify.success({title: '提示信息',message:'保存成功!'});
          this.loadingFlag = false;
          this.closeDialog('refresh');
        } else {

          this.loadingFlag = false;
        }

    },
    closeDialog(val){//关闭弹框
      this.$emit('close')
    },
    createdFrom(){
      return [
        {
            with:200,
            type: 'INPUT',
            label: '备件类别',
            fieldName: 'partTypeName',
            placeholder: '请输入',
            rules: [
                {
                  required: true,
                  message: '必填项',
                  trigger: 'blur'
                }
            ]
        }
      ]
    }
  },
}
</script>
